"""
获取搜狐网首页的新闻标题和链接（通过CSS选择器获取页面元素）

pip install BeautifulSoup4
BeautifulSoup ---> select / select_one
"""
import bs4
import requests

resp = requests.get('https://www.sohu.com/')
if resp.status_code == 200:
    soup = bs4.BeautifulSoup(resp.text, 'html.parser')
    anchors_list = soup.select('a')
    for anchor in anchors_list:
        if 'href' in anchor.attrs and 'title' in anchor.attrs:
            print(anchor.attrs['href'], anchor.attrs['title'])
